package com.dkts.oil.util;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

public class CityRegionUtil {
    public static Map<String, Object> getFenceQueryMap(Long serverId, Long userId, Long fenceId, String entityId) {
        Map<String, Object> map = new HashMap<>(16);
        map.put("fence_id", fenceId);
        map.put("disable", 0);
        map.put("service_id", serverId);
        map.put("cert_info_id", userId);
        map.put("entity_id", entityId);
        return map;
    }

    public static Map<String, List> getFenceInList(String fenceIds) {
        Map<String, List> mapLike = new HashMap<>(16);
        if (StringUtils.isNotBlank(fenceIds)) {
            mapLike.put("fence_id", Arrays.asList(fenceIds.split(",")));
        }
        return mapLike;
    }

    public static Map<String, List> getFenceInList(List fenceIds) {
        Map<String, List> mapLike = new HashMap<>(4);
        mapLike.put("fence_id", fenceIds);
        return mapLike;
    }

    public static Map<String, Object> deleteInfo() {
        Map<String, Object> mapLike = new HashMap<>(4);
        mapLike.put("disable", 0);
        return mapLike;
    }

    public static List<String> dataAreaAll(String data, List<String> noArea,String dataNew) {
        List<String> strings = new ArrayList<>(16);
        String str = StringUtils.isBlank(dataNew)?data:dataNew;
        if (StringUtils.isNotBlank(str)) {
            //先按照飞地进行分割  外圈
            String[] allArea = str.split("\\|");
            for (int i = 0; i < allArea.length; i++) {
                String[] area = allArea[i].split("\\)\\,\\(");
                strings.add(area[0]);

                int row = area.length;
                if (row > 1) {
                    for (int h = 1; h < row; h++) {
                        noArea.add(area[h]);
                    }
                }
            }
        }
        return strings;
    }

    public static String getGpsRepAll(List<String> list) {
        if(list == null){
            return null;
        }
        return String.join("|", list).replaceAll("\\,", ";").replaceAll(" ", ",");
    }

    public static String getGpsRepAll(String gpsPoints) {
        if(StringUtils.isBlank(gpsPoints)){
            return null;
        }
        return gpsPoints.replaceAll("\\,", ";").replaceAll(" ", ",");
    }
}
